//===--- ASTBridgingWrappers.def - Swift AST Metaprogramming ----*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines macros used for bridging macro-metaprogramming with AST
// nodes.
//
//===----------------------------------------------------------------------===//

/// AST_BRIDGING_WRAPPER(Name)
///   The default macro to define a bridging wrapper type.

/// AST_BRIDGING_WRAPPER_NULLABLE(Name)
///   Specifies that both a nullable and non-null variant of the wrapper should
///   be created.
#ifndef AST_BRIDGING_WRAPPER_NULLABLE
#define AST_BRIDGING_WRAPPER_NULLABLE(Name) AST_BRIDGING_WRAPPER(Name)
#endif

/// AST_BRIDGING_WRAPPER_NONNULL(Name)
///   Specifies that only a non-null variant of the wrapper should be created.
#ifndef AST_BRIDGING_WRAPPER_NONNULL
#define AST_BRIDGING_WRAPPER_NONNULL(Name) AST_BRIDGING_WRAPPER(Name)
#endif

#ifndef DECL
#define DECL(Id, Parent) AST_BRIDGING_WRAPPER_NULLABLE(Id##Decl)
#endif
#define ABSTRACT_DECL(Id, Parent) DECL(Id, Parent)
#include "swift/AST/DeclNodes.def"

#ifndef EXPR
#define EXPR(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Expr)
#endif
#define ABSTRACT_EXPR(Id, Parent) EXPR(Id, Parent)
#include "swift/AST/ExprNodes.def"

#ifndef STMT
#define STMT(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Stmt)
#endif
#define ABSTRACT_STMT(Id, Parent) STMT(Id, Parent)
#include "swift/AST/StmtNodes.def"

#ifndef TYPEREPR
#define TYPEREPR(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##TypeRepr)
#endif
#define ABSTRACT_TYPEREPR(Id, Parent) TYPEREPR(Id, Parent)
#include "swift/AST/TypeReprNodes.def"

#ifndef PATTERN
#define PATTERN(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Pattern)
#endif
#include "swift/AST/PatternNodes.def"

// Some of the base classes need to be nullable to allow them to be used as
// optional parameters.
AST_BRIDGING_WRAPPER_NONNULL(Decl)
AST_BRIDGING_WRAPPER_NONNULL(DeclContext)
AST_BRIDGING_WRAPPER_NONNULL(SourceFile)
AST_BRIDGING_WRAPPER_NULLABLE(Stmt)
AST_BRIDGING_WRAPPER_NULLABLE(Expr)
AST_BRIDGING_WRAPPER_NULLABLE(Pattern)
AST_BRIDGING_WRAPPER_NULLABLE(TypeRepr)

// Misc AST types to generate wrappers for.
AST_BRIDGING_WRAPPER_NULLABLE(GenericParamList)
AST_BRIDGING_WRAPPER_NULLABLE(TrailingWhereClause)
AST_BRIDGING_WRAPPER_NULLABLE(ParameterList)
AST_BRIDGING_WRAPPER_NONNULL(TypeAttributes)
AST_BRIDGING_WRAPPER_NONNULL(CustomAttribute)

// Non-AST types to generate wrappers for.
AST_BRIDGING_WRAPPER_NULLABLE(DiagnosticEngine)

#undef AST_BRIDGING_WRAPPER_NONNULL
#undef AST_BRIDGING_WRAPPER_NULLABLE
#undef AST_BRIDGING_WRAPPER
